package cn_dk;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Auther:dingkai
 * @date:2021/11/26 0026 下午 12:09
 * @Desc:
 */
public class MyServlet implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        System.out.println("初始化init方法");
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("我是service方法，每一次请求都会响应");
        // 获取用户提交过来的数据
        HttpServletRequest request=(HttpServletRequest) servletRequest;
        String username = request.getParameter("username");
        System.out.println(username);
        HttpServletResponse response=(HttpServletResponse) servletResponse;
        response.getWriter().print("你刚刚输入的是"+username);
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("我是destroy方法,挂掉");
    }
}
